﻿using System;
using AutoMapper;
using ORS.OrderRobot.Domain;
using ORS.OrderRobot.Domain.Entity;
using ORS.OrderRobot.ServiceContracts;
using ORS.OrderRobot.ServiceContracts.Dtos;
using ORS.OrderRobot.ServiceContracts.Dtos.Api;

namespace ORS.OrderRobot.Service
{
	public class MappingProfile : Profile
    {
        public MappingProfile()
        {
            #region 系统配置
            CreateMap<SystemConfig, SystemConfigDto>();
            CreateMap<SystemConfigDto, SystemConfig>();
            #endregion

            CreateMap<Account, AccountDto>()
                .ForMember(dest => dest.CurrentBoarding, opt => opt.Ignore());

            CreateMap<AccountBoarding, AccountBoardingDto>()
                .ForMember(dest => dest.DepartureDate, opt => opt.MapFrom(src => src.DepartureDate.ToString("yyyy/MM/dd")))
                .ForMember(dest => dest.DepartureTime, opt => opt.MapFrom(src => src.DepartureTime.ToString(@"hh\:mm")))
                .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Account.Email));
            CreateMap<AccountBoardingDto, DepatureInput>();
            CreateMap<FlightInfoDto, FlightInfo>()
                .ForMember(dest => dest.AirlineName, opt => opt.MapFrom(src =>
                    src.AirlineName != null && src.AirlineName.IndexOf(":") > -1
                        ? src.AirlineName.Substring(src.AirlineName.IndexOf(":") + 1)
                        : src.AirlineName
                ));
            CreateMap<FlightInfo, FlightInfoDto>();

            CreateMap<AccountOrder, OrderDto>()
                .ForMember(dest => dest.ProductName, opt => opt.Ignore())
                .ForMember(dest => dest.BoardingDto, opt => opt.MapFrom(src => src.AccountBoarding))
                .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Account.Email));

            CreateMap<ProductMointerLog, ProductMointerLogDto>();
            CreateMap<Admin, AdminDto>();
        }
    }
}

